<?php
session_start();
require '../nette/Nette/loader.php';
require '../db.php';
require '../localization/lang.php';
require '../core/core.sanitizer.php';
require '../core/core.security.php';
require '../core/core.dfs.php';
require '../visual/visual.dfs.php';

$login=new core_security;
if ($login->checklogin()=="OK" AND $_SESSION['role']<=1) {

$query="select login from users";
$result=mysql_query($query);

if (isset($_POST['id'])) {
$query="select * from tree where id=".mysql_real_escape_string($_POST['id'])."";
$result=mysql_query($query);
$row=mysql_fetch_array($result);

if ($row['statistics'] == 1) {
	$query="update tree set statistics=0 where id=".mysql_real_escape_string($_POST['id'])."";
	mysql_query($query);
	$query="update tree set statistics=0 where left_state > ".$row['left_state']." AND right_state < ".$row['right_state']."";
	mysql_query($query);
	}
if ($row['statistics'] == 0) {
	$query="update tree set statistics=1 where id=".mysql_real_escape_string($_POST['id'])."";
	mysql_query($query);
	$query="update tree set statistics=1 where left_state > ".$row['left_state']." AND right_state < ".$row['right_state']."";
	mysql_query($query);
	}
}
}
